package com.fifth.apartment.mapper;

import com.fifth.apartment.entity.BuildingInfo;
import com.fifth.apartment.entity.Equipment;
import com.fifth.apartment.entity.EquipmentType;
import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author author
 * @since 2024-07-09
 */
@Mapper
public interface EquipmentMapper extends MPJBaseMapper<Equipment> {

    @Select("select * from equipment_type;")
    EquipmentType[] findType();

@Select("select * from building_info")
    BuildingInfo[] findBuildingType();


@Select("SELECT e.*,et.type ,b.name as building,d.room_number as dorm,e.state,details \n" +
        "FROM equipment e\n" +
        "JOIN equipment_type et on et.id = e.type_id\n" +
        "JOIN building_info b on b.id = e.building_id\n" +
        "JOIN room_info d ON d.id = e.room_id\n" +
        "where e.id = #{id}")
    Equipment selectEquipmentByid(Integer id);



@Update("UPDATE equipment\n" +
        "set details = #{details}, state = #{state}\n" +
        "WHERE id = #{id};")
    Boolean updateDetailsById(Integer id, String details, String state);
}
